package JTable;
import javax.swing.*;

public class MyFrame extends JFrame{
    public MyFrame()
    {
        this.setSize(350,200);
        this.setTitle("JTable Demo.");
        this.setLayout(null); // 将JFrame的布局设置为空，通过坐标定位

        Object[][] rowData = new Object[][]{{"张三","男",20,"数据2305"},{"李四","女",19,"数据2305"},
                {"王五","男",21,"数据2306"},{"赵六","男",20,"数据2306"}};
        Object[] columnNames = new Object[]{"姓名","性别","年龄","所在班级"};
        JTable jtb = new JTable(rowData,columnNames);
        JScrollPane sp = new JScrollPane(jtb);
        sp.setBounds(10,20,260,80);
        this.add(sp);

        this.setLocationRelativeTo(null); // 使窗口居中
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 响应窗口关闭按钮
        this.setVisible(true); // 将窗口显示出来
    }
    public static void main(String[] args)
    {
        new MyFrame();
    }
}